package com.xhwl.centiotdata.handler.alarm.impl;

import com.alibaba.fastjson.JSONObject;
import com.xhwl.centiotdata.handler.alarm.AlarmFactory;
import com.xhwl.centiotdata.handler.alarm.AlarmHandler;
import com.xhwl.common.constant.cent.alarm.AlarmConstant;
import com.xhwl.common.dto.cent.alarm.iot.AccessInformation;
import com.xhwl.common.dto.cent.alarm.iot.IotAlarmBody;
import com.xhwl.common.dto.cent.device.DeviceDTO;
import com.xhwl.common.pojo.cent.alarm.AlarmManagement;
import org.springframework.stereotype.Component;

import java.time.ZoneId;
import java.util.Date;
import java.util.Objects;

/**
 * @Author Leon
 * @Description: TODO
 * @Date: 2022/3/22 17:30
 */
@Component
public class AlarmHuaWeiIotDAAccessInformationHandler extends AlarmHandler {
    @Override
    public void afterPropertiesSet() throws Exception {
        AlarmFactory.register("AccessInformation",this);
    }

    @Override
    public  void pushHuaWeiIotDAIotAlarmBody(IotAlarmBody t, DeviceDTO device) {
        AccessInformation accessInformation = JSONObject.parseObject(JSONObject.toJSONString(t.getProperties()), AccessInformation.class);
        if(Objects.equals(accessInformation.getEquipMentStatusDeviceStatus(),"离线")){
            AlarmManagement alarmManagement = new AlarmManagement();
            alarmManagement.setAlarmTime(Date.from(t.getEvent_time().atZone(ZoneId.systemDefault()).toInstant()));
            alarmManagement.setDeviceId(device.getId());
            alarmManagement.setProjectId(device.getProjectId());
            alarmManagement.setAlarmInventoryCode("17798944");
            sendMq(AlarmConstant.JINMAO_TOPIC,alarmManagement);
        }
    }
}
